import api from '../../../http/api.js'
import ElementUI from 'element-ui'


export default {
    // 获取优惠券表单
    async CouponManagementListData(context) {
        const res = await api.CouponManagement.CouponManagementList({
            pageNum:context.state.data.pageNum,
            page:context.state.data.pageSize
        })
        if (res.code == 200) {
            context.commit('COUPONMANAGEMENTLISTFDATA', res.data)
            console.log(res)
        }
        // console.log(context.state.data.pageSize,'context.state.data.pageSize')
    },
    // 删除当前优惠券
    async DeleteCouponId({dispatch}, value) {
        const res = await api.CouponManagement.DeleteCouponManagement(value)
        if(res.code==200){
            ElementUI.Message.success('删除成功!');
            dispatch('CouponManagementListData')
            
        }else{
            ElementUI.Message.error('删除失败!');
        }
    },
    // 新增
    async AddCouponManagements(context, value) {
        const res = await api.CouponManagement.AddCouponManagement(value)
        if(res.code==200){
            ElementUI.Message.success('新增成功!');
            
        }else{
            ElementUI.Message.error('新增失败!');
        }
    },
    // 修改显示的条数
    onshow(context,value){
        console.log(context,value)
        context.commit('ONSHOW',value);
        context.dispatch('CouponManagementListData')
    },
    // 修改当前页
    currentPage(context,value){
        context.commit("CURRENTPAGE",value)
        context.dispatch('CouponManagementListData')
    }
}